from __future__ import division
from models import Track
	
def prepareForCompare(tracklist):
	#takes a list of track objects and does crunching on the title and artist
	for track in tracklist:
		track.title = track.title.lower()
		track.artist = track.artist.lower()
		track.title = track.title.replace(" ","")
		track.artist = track.artist.replace(" ","")
		track.title = track.title.replace("'","")
		track.artist = track.artist.replace("'","")
		if track.artist.startswith("the"):
			track.artist = track.artist.replace("the","", 1)
		
	return tracklist
	
def artistList(tracklist):
	mymap = {}
	for t in tracklist:
		mymap[t.artist] = "foo"
	
	return mymap.keys()
	
def percentArtistOverlap(tl1,tl2):
	myartists = artistList(tl1)
	theirartists = artistList(tl2)
	artistmap = {} #ready to put some artists on the map, har har
	for a in myartists:
		artistmap[a] = "foo"
	
	overlapcount = 0
	
	for a in theirartists:
		if a in artistmap:
			overlapcount = overlapcount + 1
	
	myartists_len = len(myartists)
	if myartists_len > 0:
		thenumber = (overlapcount/myartists_len) * 100
	else:
		thenumber = 0	
	return thenumber

	
	
	
	
